﻿<%@ CODEPAGE=65001 %>
<%
'///////////////////////////////////////////////////////////////////////////////
'// 插件应用:    Z-Blog 2.0 其它版本未知
'// 插件制作:    狼的旋律(http://www.wilf.cn) / zsx(http://www.zsxsoft.com)
'// 备    注:    修改图片信息保存、设置封面、删除
'// 最后修改:
'// 最后版本:
'///////////////////////////////////////////////////////////////////////////////
%>
<% Option Explicit %>
<% 'On Error Resume Next %>
<% Response.Charset="UTF-8" %>
<% Response.Buffer=True %>
<!-- #include file="../../c_option.asp" -->
<!-- #include file="../../../zb_system/function/c_function.asp" -->
<!-- #include file="../../../zb_system/function/c_system_lib.asp" -->
<!-- #include file="../../../zb_system/function/c_system_base.asp" -->
<!-- #include file="../../../zb_system/function/c_system_plugin.asp" -->
<!-- #include file="../p_config.asp" -->
<%
Call System_Initialize()
Call WindsPhoto_Initialize()

Call CheckReference("")

If BlogUser.Level>2 Then Call ShowError(6)
If CheckpluginState("windsphoto") = False Then Call ShowError(48)

Dim action,id,typeid
If Request.Form("action") = "" Then
    action = Request.QueryString("action")
Else
    action = Request.Form("action")
End If
id = Request.QueryString("id")
If Request.Form("typeid") = "" Then
    typeid = Request.QueryString("typeid")
Else
    typeid = Request.Form("typeid")
End If
If action="" Then
    Call SetBlogHint_Custom("!! 参数错误.")
    Response.Redirect "admin_main.asp"
End If

Select Case action

	Case "sethot" Call SetHot()
	Case "delphoto" Call DelPhoto()
	Case "batchdel" Call BatchDel()
	Case "batchmove" Call BatchMove()
	Case "editphoto" Call EditPhoto()
	Case "editalbum" Call EditAlbum()
	Case "addalbum" Call AddAlbum()
	Case "delalbum" Call DelAlbum()
	Case "updatecache" Call UpdateCache()
	Case "savesetting" Call SaveSetting()

End Select

Function SetHot

	objconn.Execute ("UPDATE WindsPhoto_desktop SET [hot]='1' WHERE [id]="&id)
	objconn.Execute ("UPDATE WindsPhoto_desktop SET [hot]='0' WHERE [zhuanti]="&typeid&" AND [id]<>"&id)
	'Call SetBlogHint_Custom("√ 设置封面成功.")
	Call SetBlogHint(True,False,False)
	Response.Redirect "admin_addphoto.asp?typeid="&typeid&"#manage"

End Function

Function DelPhoto

    Dim temprs,url,surl

	Set temprs = objConn.Execute("select * FROM WindsPhoto_desktop where id="&id)
    url = temprs("url")
    surl = temprs("surl")
    If Left(url, 4)<>"http" Then
		Call DelToFile(BlogPath&"/zb_users/plugin/windsphoto/"&url)
		Call DelToFile(BlogPath&"/zb_users/plugin/windsphoto/"&surl)
    End If
	Set temprs = Nothing
    objConn.Execute("delete FROM WindsPhoto_desktop where id="&id)

	Call WindsPhoto_SaveNewestlist()
	'Call SetBlogHint_Custom("√ 删除成功.")
	Call SetBlogHint(True,True,False)
	Response.Redirect "admin_addphoto.asp?typeid="&typeid&"#manage"

End Function

Function BatchDel

	Dim s,t,j,temprs,url,surl

	s=Request.Form("edtBatch")
	t=Split(s,",")

	For j=0 To UBound(t)-1
		t(j)=CLng(t(j))
		If t(j)>0 Then
			Set temprs = objConn.Execute("select * FROM WindsPhoto_desktop where id="&t(j))
			url = temprs("url")
			surl = temprs("surl")
			If Left(url, 4)<>"http" Then
				Call DelToFile(BlogPath&"/zb_users/plugin/windsphoto/"&url)
				Call DelToFile(BlogPath&"/zb_users/plugin/windsphoto/"&surl)
			End If
			objConn.Execute("delete FROM WindsPhoto_desktop where id="&t(j))
			Set temprs = Nothing
		End If
	Next

	Call WindsPhoto_SaveNewestlist()
	'Call SetBlogHint_Custom("√ 删除成功.")
	Call SetBlogHint(True,True,False)
	Response.Redirect "admin_addphoto.asp?typeid="&typeid&"#manage"

End Function

Function BatchMove

	Dim s,t,j,n

	s=Request.Form("edtBatch")
	t=Split(s,",")
	n=Request.Form("new_typeid")

	For j=0 To UBound(t)-1
		t(j)=CLng(t(j))
		If t(j)>0 Then
			objConn.Execute("UPDATE WindsPhoto_desktop SET zhuanti='"&n&"' where id="&t(j))
		End If
	Next

	'Call SetBlogHint_Custom("√ 移动成功.")
	Call SetBlogHint(True,True,False)
	Response.Redirect "admin_addphoto.asp?typeid="&typeid&"#manage"

End Function

Function EditPhoto

    Dim rs,sql,itime,temprs,name,category

	Set rs = Server.CreateObject("ADODB.Recordset")
    sql = "select * FROM WindsPhoto_desktop where id="&id
    rs.Open sql, objConn, 1, 3
    rs("name") = Request.Form("name")
    rs("url") = Request.Form("url")
    rs("surl") = Request.Form("surl")
    rs("zhuanti") = Request.Form("zhuanti")
    rs("hot") = Request.Form("hot")
    rs("jj") = Request.Form("jj")
    If Request.Form("itime")<>"" Then itime = Request.Form("itime") Else itime = now()
    rs("itime") = itime
    rs.update
    rs.Close
    Set rs = Nothing

    'Call SetBlogHint_Custom("√ 编辑图片信息成功.</a>")
	Call SetBlogHint(True,False,False)
    Response.Redirect "admin_addphoto.asp?typeid="&Request.Form("zhuanti")&"#manage"

End Function

Function EditAlbum

	If Trim(Request.Form("name")) = "" Then
		Call SetBlogHint_Custom("相册名不能为空")
		Response.Redirect "admin_main.asp"
		Response.End
	End If

	Dim rs,sql,temprs,sm,ordered

	Set rs = Server.CreateObject("ADODB.Recordset")
	sql = "SELECT * FROM WindsPhoto_zhuanti where id="&typeid
	rs.Open sql, objConn, 1, 3
	rs("name") = Request.Form("name")
	rs("js") = Request.Form("js")
	rs("pass") = Request.Form("pass")
	rs("view") = Request.Form("view")
	If Request.Form("ordered") = "" Then
		Set temprs = objConn.Execute("select count(*) as C FROM WindsPhoto_zhuanti")
		sm = temprs("C")
		ordered = sm + 1
	Else
		ordered = Request.Form("ordered")
	End If
	rs("ordered") = ordered
	rs.update
	rs.Close
	Set rs = Nothing

	Call WindsPhoto_SaveAlbumList()
	'Call SetBlogHint_Custom("√ 编辑相册分类成功.")
	Call SetBlogHint(True,True,False)
	Response.Redirect "admin_main.asp"

End Function

Function AddAlbum

	If Trim(Request.Form("name")) = "" Then
		Call SetBlogHint_Custom("相册名不能为空")
		Response.Redirect "admin_main.asp"
		Response.End
	End If

	Dim rs,sql,temprs,sm,ordered

	Set rs = Server.CreateObject("ADODB.Recordset")
	sql = "SELECT * FROM WindsPhoto_zhuanti where (id is null)"
	rs.Open sql, objConn, 1, 3
	rs.addnew
	rs("name") = Request.Form("name")
	rs("js") = Request.Form("js")
	rs("pass") = Request.Form("pass")
	rs("view") = Request.Form("view")
	If Request.Form("ordered") = "" Then
		Set temprs = objConn.Execute("select count(*) as C FROM WindsPhoto_zhuanti")
		sm = temprs("C")
		ordered = sm + 1
	Else
		ordered = Request.Form("ordered")
	End If
	rs("ordered") = ordered
	rs.update
	rs.Close
	Set rs = Nothing

	Call WindsPhoto_SaveAlbumList()
	'Call SetBlogHint_Custom("√ 添加相册分类成功.")
	Call SetBlogHint(True,True,False)
	Response.Redirect "admin_main.asp"

End Function

Function DelAlbum

    Dim temprs,surl,url

	objConn.Execute "delete FROM WindsPhoto_zhuanti where id="&typeid
	Set temprs = objConn.Execute("select * FROM WindsPhoto_desktop where zhuanti="&typeid)
	Do While Not temprs.EOF
		surl = temprs("surl")
		url = temprs("url")
		If Left(url, 4)<>"http" Then
			Call DelToFile(BlogPath&"/zb_users/plugin/windsphoto/"&url)
			Call DelToFile(BlogPath&"/zb_users/plugin/windsphoto/"&surl)
		End If
		temprs.movenext
	Loop
    objConn.Execute "delete FROM WindsPhoto_desktop where zhuanti="&typeid
    Call WindsPhoto_SaveAlbumList()
	'Call SetBlogHint_Custom("√ 删除相册分类成功.")
	Call SetBlogHint(True,True,False)
    Response.Redirect "admin_main.asp"

End Function

Function UpdateCache

	Call WindsPhoto_SaveAlbumlist()
	Call WindsPhoto_SaveNewestlist()
	'Call SetBlogHint_Custom("√ 操作成功.")
	Call SetBlogHint(True,True,False)
	Response.Redirect "admin_main.asp"

End Function

Function SaveSetting

	Dim strWP_ALBUM_NAME,strWP_SCRIPT_TYPE,strWP_WATERMARK_TYPE,strWP_ORDER_BY,strWP_UPLOAD_DIR,strWP_UPLOAD_DIRBY,strWP_THUMB_TYPE,strWP_JPEG_FONTFAMILY,strWP_JPEG_FONTBOLD,strWP_JPEG_FONTITALIC,strWP_JPEG_FONTQUALITY,strWP_JPEG_FONTSIZE,strWP_JPEG_FONTCOLOR,strWP_WATERMARK_TEXT,strWP_JPEG_QUALITY,strWP_WATERMARK_WIDTH_POSITION,strWP_WATERMARK_HEIGHT_POSITION,strWP_SMALL_WIDTH,strWP_SMALL_HEIGHT,strWP_LIST_WIDTH,strWP_WATERFLOW_WIDTH,strWP_WATERMARK_LOGO,strWP_WATERMARK_ALPHA,strWP_INDEX_PAGERCOUNT,strWP_SMALL_PAGERCOUNT,strWP_LIST_PAGERCOUNT,strWP_SUB_DOMAIN,strWP_ALBUM_INTRO,strWP_UPLOAD_RENAME,strWP_WATERMARK_AUTO,strWP_BLOGPHOTO_ID,strWP_EXIF_ITEMS,strWP_CAMERA_MODEL,strWP_JPEG_WIDTH,strWP_JPEG_MAXWIDTH

	strWP_ALBUM_NAME = Request.Form("strWP_ALBUM_NAME")
	strWP_SCRIPT_TYPE = Replace(Replace(Request.Form("strWP_SCRIPT_TYPE"), VBCRLF, ""), VBLF, "")
	strWP_WATERMARK_TYPE = Replace(Replace(Request.Form("strWP_WATERMARK_TYPE"), VBCRLF, ""), VBLF, "")
	strWP_ORDER_BY = Replace(Replace(Request.Form("strWP_ORDER_BY"), VBCRLF, ""), VBLF, "")
	strWP_UPLOAD_DIR = Request.Form("strWP_UPLOAD_DIR")
	strWP_UPLOAD_DIRBY = Request.Form("strWP_UPLOAD_DIRBY")
	strWP_THUMB_TYPE = Request.Form("strWP_THUMB_TYPE")
	strWP_JPEG_FONTFAMILY = Request.Form("strWP_JPEG_FONTFAMILY")
	strWP_JPEG_FONTBOLD = Request.Form("strWP_JPEG_FONTBOLD")
	strWP_JPEG_FONTITALIC = Request.Form("strWP_JPEG_FONTITALIC")
	strWP_JPEG_FONTQUALITY = Request.Form("strWP_JPEG_FONTQUALITY")
	strWP_JPEG_FONTSIZE = Request.Form("strWP_JPEG_FONTSIZE")
	strWP_JPEG_FONTCOLOR = Request.Form("strWP_JPEG_FONTCOLOR")
	strWP_WATERMARK_TEXT = Request.Form("strWP_WATERMARK_TEXT")
	strWP_JPEG_QUALITY = Request.Form("strWP_JPEG_QUALITY")
	strWP_WATERMARK_WIDTH_POSITION = Request.Form("strWP_WATERMARK_WIDTH_POSITION")
	strWP_WATERMARK_HEIGHT_POSITION = Request.Form("strWP_WATERMARK_HEIGHT_POSITION")
	strWP_SMALL_WIDTH = Request.Form("strWP_SMALL_WIDTH")
	strWP_SMALL_HEIGHT = Request.Form("strWP_SMALL_HEIGHT")
	strWP_LIST_WIDTH = Request.Form("strWP_LIST_WIDTH")
	strWP_WATERFLOW_WIDTH = Request.Form("strWP_WATERFLOW_WIDTH")
	strWP_WATERMARK_LOGO = Request.Form("strWP_WATERMARK_LOGO")
	strWP_WATERMARK_ALPHA = Request.Form("strWP_WATERMARK_ALPHA")
	strWP_INDEX_PAGERCOUNT = Request.Form("strWP_INDEX_PAGERCOUNT")
	strWP_SMALL_PAGERCOUNT = Request.Form("strWP_SMALL_PAGERCOUNT")
	strWP_LIST_PAGERCOUNT = Request.Form("strWP_LIST_PAGERCOUNT")
	strWP_SUB_DOMAIN = Request.Form("strWP_SUB_DOMAIN")
	strWP_ALBUM_INTRO = Request.Form("strWP_ALBUM_INTRO")
	strWP_UPLOAD_RENAME = Request.Form("strWP_UPLOAD_RENAME")
	strWP_WATERMARK_AUTO = Request.Form("strWP_WATERMARK_AUTO")
	strWP_BLOGPHOTO_ID = Request.Form("strWP_BLOGPHOTO_ID")
	strWP_EXIF_ITEMS = Request.Form("strWP_EXIF_ITEMS")
	strWP_CAMERA_MODEL = Request.Form("strWP_CAMERA_MODEL")
	strWP_JPEG_WIDTH = Request.Form("strWP_JPEG_WIDTH")
	strWP_JPEG_MAXWIDTH = Request.Form("strWP_JPEG_MAXWIDTH")

	If IsNumeric(strWP_JPEG_QUALITY) = False Or IsNumeric(strWP_INDEX_PAGERCOUNT) = False Or IsNumeric(strWP_SMALL_PAGERCOUNT) = False Or IsNumeric(strWP_LIST_PAGERCOUNT) = False Or IsNumeric(strWP_SMALL_WIDTH) = False Or IsNumeric(strWP_SMALL_HEIGHT) = False Or IsNumeric(strWP_LIST_WIDTH) = False Or IsNumeric(strWP_WATERFLOW_WIDTH) = False Or IsNumeric(strWP_JPEG_FONTSIZE) = False Or IsNumeric(strWP_JPEG_FONTQUALITY) = False Or IsNumeric(strWP_WATERMARK_ALPHA) = False Or IsNumeric(strWP_JPEG_WIDTH) = False Then ShowError(3)

	WP_Config.Write "WP_SCRIPT_TYPE",strWP_SCRIPT_TYPE
	WP_Config.Write "WP_WATERMARK_TYPE",strWP_WATERMARK_TYPE
	WP_Config.Write "WP_ORDER_BY",strWP_ORDER_BY
	WP_Config.Write "WP_UPLOAD_DIR",strWP_UPLOAD_DIR
	WP_Config.Write "WP_UPLOAD_DIRBY",strWP_UPLOAD_DIRBY
	WP_Config.Write "WP_THUMB_TYPE",strWP_THUMB_TYPE
	WP_Config.Write "WP_JPEG_FONTFAMILY",strWP_JPEG_FONTFAMILY
	WP_Config.Write "WP_JPEG_FONTBOLD",strWP_JPEG_FONTBOLD
	WP_Config.Write "WP_JPEG_FONTITALIC",strWP_JPEG_FONTITALIC
	WP_Config.Write "WP_JPEG_FONTQUALITY",strWP_JPEG_FONTQUALITY
	WP_Config.Write "WP_JPEG_FONTSIZE",strWP_JPEG_FONTSIZE
	WP_Config.Write "WP_JPEG_FONTCOLOR",strWP_JPEG_FONTCOLOR
	WP_Config.Write "WP_WATERMARK_TEXT",strWP_WATERMARK_TEXT
	WP_Config.Write "WP_ALBUM_NAME",strWP_ALBUM_NAME
	WP_Config.Write "WP_WATERMARK_WIDTH_POSITION",strWP_WATERMARK_WIDTH_POSITION
	WP_Config.Write "WP_WATERMARK_HEIGHT_POSITION",strWP_WATERMARK_HEIGHT_POSITION
	WP_Config.Write "WP_JPEG_QUALITY",strWP_JPEG_QUALITY
	WP_Config.Write "WP_SMALL_WIDTH",strWP_SMALL_WIDTH
	WP_Config.Write "WP_SMALL_HEIGHT",strWP_SMALL_HEIGHT
	WP_Config.Write "WP_LIST_WIDTH",strWP_LIST_WIDTH
	WP_Config.Write "WP_WATERFLOW_WIDTH",strWP_WATERFLOW_WIDTH
	WP_Config.Write "WP_WATERMARK_LOGO",strWP_WATERMARK_LOGO
	WP_Config.Write "WP_WATERMARK_ALPHA",strWP_WATERMARK_ALPHA
	WP_Config.Write "WP_INDEX_PAGERCOUNT",strWP_INDEX_PAGERCOUNT
	WP_Config.Write "WP_SMALL_PAGERCOUNT",strWP_SMALL_PAGERCOUNT
	WP_Config.Write "WP_LIST_PAGERCOUNT",strWP_LIST_PAGERCOUNT
	WP_Config.Write "WP_SUB_DOMAIN",strWP_SUB_DOMAIN
	WP_Config.Write "WP_ALBUM_INTRO",strWP_ALBUM_INTRO
	WP_Config.Write "WP_UPLOAD_RENAME",strWP_UPLOAD_RENAME
	WP_Config.Write "WP_WATERMARK_AUTO",strWP_WATERMARK_AUTO
	WP_Config.Write "WP_BLOGPHOTO_ID",strWP_BLOGPHOTO_ID
	WP_Config.Write "WP_EXIF_ITEMS",strWP_EXIF_ITEMS
	WP_Config.Write "WP_CAMERA_MODEL",strWP_CAMERA_MODEL
	WP_Config.Write "WP_JPEG_WIDTH",strWP_JPEG_WIDTH
	WP_Config.Write "WP_JPEG_MAXWIDTH",strWP_JPEG_MAXWIDTH
	WP_Config.Save

	Call SetBlogHint(True,False,False)
	Response.Redirect "admin_setting.asp"

End Function

Call System_Terminate()
%>